package org.metasketch.simulator.tools.generic;

import java.util.List;

import org.metasketch.simulator.resources.ResourceBank;
import org.metasketch.simulator.tools.Registry;

public class GenericInfoValidator {

	public static void validate(GenericInfo info, Registry reg,
			ResourceBank bank) throws Exception {

		List<Variable> variables = info.getVariables();

		if (variables != null)
			for (Variable variable : variables) {

				if (variable.getName().contains(" ")) {
					throw new Exception(
							"Variable names cannot contain spaces: "
									+ variable.getName());
				}

			}

		List<ResourceRequirement> reqs = info.getRequirements();
		if (reqs != null)
			for (ResourceRequirement req : reqs) {

				if (reg.get(req.getAlias()) == null)
					throw new Exception(
							"No resource requirement found with the name of: "
									+ req.getAlias());

			}

		List<ResourceProduction> prods = info.getProductions();
		if (prods != null)
			for (ResourceProduction prod : prods) {

				if (reg.get(prod.getAlias()) == null)
					throw new Exception(
							"No resource production found with the name of: "
									+ prod.getAlias());

			}

	}
}
